package com.powergisol.gis.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.powergisol.gis.vo.B3DMJsonData;
import com.powergisol.gis.vo.FeatureType;
import com.powergisol.gis.vo.LOBJsonData;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

/**
 * Date: 2019/8/21  17:34
 * Description:
 */
public class FileRead {


    public static LOBJsonData fileReadLob(String url) throws IOException {
        File file = new File(url);
        String jsonString = FileUtils.readFileToString(file,"UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(jsonString);
        LOBJsonData data = JSON.toJavaObject(jsonObject,LOBJsonData.class);
        return data;
    }
    public static B3DMJsonData fileReadB3dm(String url) throws IOException {
        File file = new File(url);
        String jsonString = FileUtils.readFileToString(file,"UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(jsonString);
        B3DMJsonData data = JSON.toJavaObject(jsonObject,B3DMJsonData.class);
        return data;
    }
//    public static OSGBTB3dmJsonData fileReadOSGBtB3dm(String url) throws IOException {
//        File file = new File(url);
//        String jsonString = FileUtils.readFileToString(file,"UTF-8");
//        JSONObject jsonObject = JSONObject.parseObject(jsonString);
//        OSGBTB3dmJsonData data = JSON.toJavaObject(jsonObject,OSGBTB3dmJsonData.class);
//        return data;
//    }

    public static void main(String[] args) throws IOException {
        B3DMJsonData data = fileReadB3dm("E:\\tileset.json");
        System.out.println(data);
//        FeatureType featureType = new FeatureType();
//        LOBJsonData data = fileReadLob("E:\\model.json");
//        LOBJsonData.DataDefineBean.RangeBean rangeBean = data.getDataDefine().getRange();
//        double minx = Double.valueOf(rangeBean.getWest());
//        double maxx = Double.valueOf(rangeBean.getEast());
//        double miny = Double.valueOf(rangeBean.getSouth());
//        double maxy = Double.valueOf(rangeBean.getNorth());
//        FeatureType.NativeBoundingBox nativeBoundingBox =
//                new FeatureType.NativeBoundingBox(minx,maxx,miny,maxy,null);
//        featureType.setNativeBoundingBox(nativeBoundingBox);
//        File file = new File("E:/crs.json");
//        String jsonString = FileUtils.readFileToString(file,"UTF-8");
//        String str[] = jsonString.replace("[{","").replace("}]","").replace("}","").split(", \\{");
//        String attr = str[0];
//        String att[] = attr.split(", \"");
//        String a = att[2].substring(6,att[2].length()-1);
//        String b[] =a.split("UNIT");
//        String c = att[3];
//        System.out.println(c);
        //System.out.println(b[2].split("]")[0].split(",")[0].replace("[","").replaceAll("\"",""));
    }
}
